/**
 * Copyright (C), 2015-2021, XXX有限公司
 * FileName: VolatileVisibilityTest
 * Author:   AEO WUGUOZHI
 * Date:     2021/3/8 22:08
 * Description: 高并发 volatile的可见性
 * History:
 * <author>          <time>          <version>          <desc>
 * 作者姓名           修改时间           版本号              描述
 */
package com.bnuz;

import com.sun.xml.internal.ws.api.message.Message;

/**
 * 〈一句话功能简述〉<br> 
 * 〈高并发 volatile的可见性〉
 *
 * @author AEO WUGUOZHI
 * @create 2021/3/8
 * @since 1.0.0
 */
public class VolatileVisibilityTest {

    public static volatile boolean initFlag = false;

    public static void main(String[] args) throws InterruptedException {
        new Thread(new Runnable(){
            @Override
            public void run(){
                System.out.println("waiting data......");
                while(!initFlag){

                }
                System.out.println("---------------success!");
            }
        }).start();

        Thread.sleep(2000);

        new Thread(new Runnable() {
            @Override
            public void run() {
                prepareData();
            }

        }).start();


    }

    private static void prepareData() {
        System.out.println("prepareing data.....");
        initFlag = true;
        System.out.println("prepare data end.....");
    }
}